//
//  statusRetweetedView.swift
//  NSinaWeibo
//
//  Created by LoliQueen on 16/2/22.
//  Copyright © 2016年 LoliQueen. All rights reserved.
//

import UIKit
import SnapKit

class statusRetweetedView: UIView {

    
    var bottomConstraint : Constraint?
    var retweetedStatus : Status?{
        didSet{
            //设置数据
            retweetedLabel.text = retweetedStatus?.text
            pictureView.pictureUrls = retweetedStatus?.pictureUrls
            
            ///根据是否有图片地址，判断底部约束
            self.bottomConstraint?.uninstall()
            if let imageUrls = retweetedStatus?.pictureUrls where imageUrls.count != 0{
                ///有图片
                self.snp_makeConstraints { (make) -> Void in
                   self.bottomConstraint =  make.bottom.equalTo(pictureView.snp_bottom).offset(picMargin).constraint
                }
                
            }else{
                self.snp_makeConstraints { (make) -> Void in
           self.bottomConstraint =  make.bottom.equalTo(retweetedLabel.snp_bottom).offset(picMargin).constraint
                }
            }
        }
        
    }
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        setUpUI()
    }
    
    
    //设置子控件位置
    private func setUpUI(){
        addSubview(retweetedLabel)
        addSubview(pictureView)
        
        retweetedLabel.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(self.snp_top)
            make.left.equalTo(self.snp_left).offset(homeVCMargin)
            make.right.equalTo(self.snp_right).offset(-homeVCMargin)
        }
        
        pictureView.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(retweetedLabel.snp_bottom).offset(picMargin)
            make.left.equalTo(retweetedLabel.snp_left)
        }
        
        ///约束转发微博视图的高度
        self.snp_makeConstraints { (make) -> Void in
           self.bottomConstraint = make.bottom.equalTo(pictureView.snp_bottom).offset(picMargin).constraint
        }
        
    }
    
    
    ///懒加载子控件
    lazy var retweetedLabel : UILabel = UILabel(title: "abcdefg", textSize: 14, textColor: UIColor.lightGrayColor(), aligmen: NSTextAlignment.Left)
    
    lazy var pictureView : statusPictureView = statusPictureView()

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

}
